Repository navigation
Map::Units: two TribesState functions back to 100%, predatorNearby tested for non-zero - #483
Merged
Merged
Conversation
…again The original tests the tribe's predatorNearby with `cmp word ptr [eax + ecx + 0x2a0], 0` and `jne` (0x005260D3, 0x005260E0). gynt's first version had `!= 0` and read 100%. 374411d (2026-11-09) wrote `> 0`, because the field is not a flag: it counts the ticks since the herd was scared. On the ushort, `> 0` compiles to `ja`, the function's one differing instruction in a full build (98.7% raw, 95.2% normalised). `!= 0` is the same test on a ushort and gives the original's `jne`; a one-line comment says why. The tick counter's `field_0x288 = field_0x288 + 1` is `++field_0x288`, as the style fixer writes it (the same listing). No other change. Measured: a real build (main's /GL list and the two files of this branch, with the struct resolvers and those files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every other function reads as in the same build without them. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The original tests the tribe's predatorNearby with `cmp word ptr [eax + 0x2a0], 0` and `jne` (0x005235AA, 0x005235B6). gynt's first version had `== 0` (then `!= 0`) and read 100%. 374411d (2026-11-09) wrote `> 0`, because the field is not a flag: it counts the ticks since the herd was scared. On the ushort, `> 0` compiles to `ja`, the function's one differing instruction in a full build (98.0% raw, 95.2% normalised). `!= 0` is the same test on a ushort and gives the original's `jne`; a one-line comment says why. The unit loop is a `for` now, as the style guide asks. Its index still steps in the body, right after the call, as the original's `add esi, 1` at 0x005235D4 does (stepped in the loop's header, the match is lost), and it is written `++unitSelectionIndex`, as the style fixer writes it. No other change. Measured: a real build (main's /GL list and the two files of this branch, with the struct resolvers and those files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every other function reads as in the same build without them. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two of gynt's TribesState functions from #277 read below 100% in a full build of main (with #478's four unrelated fixes on top) with every resolver on, although their status lines say 100%. In both, one conditional jump differs (
jawhere the original hasjne), and the change is the same one-line test. No header change, no line forcmake/compiler-flags-gl.txt, and the status lines stay as they are (100.0%).TribesState::trySpawnAdditionalWildlifeForTribeTribesState::updateAnimalHerdBehaviorStateBoth commits credit gynt as co-author.
predatorNearbytested for non-zeropredatorNearbyagainst 0 withjnein both:cmp word ptr [eax + ecx + 0x2a0], 0at 0x005260D3 withjneat 0x005260E0, andcmp word ptr [eax + 0x2a0], 0at 0x005235AA withjneat 0x005235B6.predatorScareTimer) or to put the explicit!= 0back, and then wrote the two tests as> 0(374411d, 2026-11-09). On theushortfield,> 0compiles toja, and that one jump is each function's whole difference. His explicit tests against 0 before that read 100%:!= 0in trySpawnAdditionalWildlifeForTribe (7a1d6aa), and== 0in updateAnimalHerdBehaviorState's first version (7a1d6aa), then!= 0(1d394e6). Between those and> 0, 5524e2a had made both tests bare truth tests.!= 0, the other form gynt offered: on an unsigned counter it gives the same answer as> 0for every value. It is the test the original makes (whether a scare is running, not how far along it is), and it stays an explicit comparison, as the style guide's rule 5 keeps for counters, so it does not read as a flag. Each has a one-line comment saying so, so that it isn't changed back to> 0or to a bare truth test.predatorNearbykeeps its name here, because renaming it is aTribe.hppchange that also touchesUpdateDeer.cppand the drafts in Reimpl/TribesState development #279. It changes no code, so we can add it here as a header commit (predatorScareTimer, as gynt suggested) if you would like it now, or leave it for the Ghidra sync.Style fixes in the touched files
updateAnimalHerdBehaviorState's unit loop is afor, as the style guide asks. Its index still steps in the body, right after the call, as the original'sadd esi, 1at 0x005235D4 does; stepped in the loop's header, the match is lost. A one-line comment says so.x = x + 1steps are++x(the style guide's rule 29; prefix, as everywhere on main; the same listing).field_0x288keeps its placeholder name: it counts the ticks towardsspawnIntervalTicksand is cleared when they are reached. Naming it is a header change, so it is left for the Ghidra sync.Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), the struct resolvers and the function resolvers enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLlist (neither file is on it), and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,425 compile steps, 99.58 over 2,441 functions.trySpawnAdditionalWildlifeForTribeandupdateAnimalHerdBehaviorStateread 100.0 raw and normalised there, with no diff entry (98.7 and 98.0, both 95.2 normalised, in the same build of main). Two main functions read lower, and it is how reccmp prints a constant, not their code:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all; in this build's layout a symbol of our DLL lies at exactly that address, so reccmp prints the constant as that symbol's name on our side, and the instructions are the same on both sides (UI: the single-player game launch at 100% #466 describes the same two readings). Every other function reads exactly what it read before; against main's own build (made at f489b72, 2,439 functions) the only other changes are main's since then (One more UI::MenuModals function at 100%: ProgressBarBox #467'sMenuModalRenderFunction_ProgressBarBoxand its constructor, UI: the single-player game launch at 100% #466'sLaunchSinglePlayerGameUnk) (unrounded 99.5787 raw and 99.5512 normalised, 2,325 functions at 100.0 raw; with those two at 100.0, 99.5802 and 99.5567, 2,327; main 0e4a83b alone: 99.5788 and 99.5528 over 2,441, 2,325 at 100.0)./GLlist (the 133 files that exist) and the two files in this PR's texts (built before the last change to the twopredatorNearbycomments, which leaves the listing the same), with their resolvers on: each of the two reads 100.0% raw and normalised with no diff entry, and every other function reads as in the same build without them.field_0x288, below). Our local fixer finds nothing to change.Looked at in the same pass, nothing to change in the source
Other functions on main that read below 100% only because reccmp names an operand on one side and not the other (the instructions and addresses agree):
moveTribeToNearbyClearTile(98.4%): the loop's end address (the table's end + 4) is namedcached+4on our side and not named on the original's. Both loops anchor the pointer onXYPair::yand run 0x140 bytes, so main's status remark ("anchors on XYPair::x") describes an earlier version; gynt's Reimpl/TribesState methods that are 100% #277 note on the end address's encoding is the current reading. We left the line alone, since Reimpl/TribesState development #279 changes the lines next to it; happy to correct it here if you prefer.TicksSinceCounterStart(88.7%): the performance counter's address, which reccmp does not pair although it prints the same name on both sides, and the float constants.RenderHistoryBookEdgeUnk(85.7%): the float constants and_ftol2_sse.initializeDirectDraw(99.2%),createDirectPlayInterfaceModem(98.7%) andcreateWindow(98.4%): the DirectDraw and DirectPlay import thunks and the callbacks' trampolines.RenderActiveCreditsElements(95.0%):_ftol2_sse, the float constants and the loop's end address.PlayJokeVideoBasedOnCurrentTimeAndPlayTime(91.3%): the 26 operands intoFLAG_JokeAIMessageArray, not named on the original's side.🤖 Generated with Claude Code